package com.qlk.odcinterface.service.impl;

import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsFullCut;
import com.qlk.odcinterface.domain.query.PmsFullCutQuery;
import com.qlk.odcinterface.manager.PmsFullCutManager;
import com.qlk.odcinterface.sdk.api.request.PmsFullCutRequest;
import com.qlk.odcinterface.service.PmsFullCutService;
import com.qlk.odcinterface.utils.exceptions.ExistedException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.perf4j.aop.Profiled;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * PmsFullCutService接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 17:10:21
 * 
 */
@Service
public class PmsFullCutServiceImpl implements PmsFullCutService {

    /** LOG */
    private static final Log LOG = LogFactory.getLog(PmsFullCutServiceImpl.class);

    @Autowired
    private PmsFullCutManager pmsFullCutManager;

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.batchInsert")
    public boolean insert(List<PmsFullCut> pmsFullCutList) {
        boolean resultFlag = false;
        try {
            if (CollectionUtils.isNotEmpty(pmsFullCutList)) {
                resultFlag = pmsFullCutManager.insert(pmsFullCutList);
            } else {
                LOG.warn("PmsFullCutServiceImpl#batchInsert failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#batchInsert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.insert")
    public boolean insert(PmsFullCut pmsFullCut) {
        boolean resultFlag = false;
        try {
            if (null != pmsFullCut) {
                if (pmsFullCutManager.exist(pmsFullCut)) {
                    throw new ExistedException();
                }
                resultFlag = pmsFullCutManager.insert(pmsFullCut);
            } else {
                LOG.warn("PmsFullCutServiceImpl#insert failed, param is illegal.");
            }
        } catch (ExistedException e) {
            LOG.warn("PmsFullCutServiceImpl#insert failed, pmsFullCut has existed.");
            throw e;
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#insert has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.update")
    public boolean update(PmsFullCut pmsFullCut) {
        boolean resultFlag = false;
        try {
            if (null != pmsFullCut && null != pmsFullCut.getId()) {
                resultFlag = pmsFullCutManager.update(pmsFullCut);
            } else {
                LOG.warn("PmsFullCutServiceImpl#update failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#update has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.queryPmsFullCutList")
    public List<PmsFullCut> queryPmsFullCutList(PmsFullCutQuery queryBean) {
        List<PmsFullCut> pmsFullCutList = null;
        try {
            pmsFullCutList = pmsFullCutManager.queryPmsFullCutList(queryBean);
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#queryPmsFullCutList has error.", e);
        }
        return pmsFullCutList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.queryPmsFullCutListWithPage")
    public List<PmsFullCut> queryPmsFullCutListWithPage(PmsFullCutQuery queryBean, PageUtil pageUtil) {
        List<PmsFullCut> pmsFullCutList = null;
        try {
            pmsFullCutList = pmsFullCutManager.queryPmsFullCutListWithPage(queryBean, pageUtil);
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#queryPmsFullCutListWithPage has error.", e);
        }
        return pmsFullCutList;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.delete")
    public boolean delete(PmsFullCut pmsFullCut) {
        boolean resultFlag = false;
        try {
            if (null != pmsFullCut && null != pmsFullCut.getId()) {
                resultFlag = pmsFullCutManager.delete(pmsFullCut);
            } else {
                LOG.warn("PmsFullCutServiceImpl#delete param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#delete has error.", e);
        }
        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.batchDelete")
    public boolean delete(PmsFullCut[] pmsFullCuts) {
        boolean resultFlag = false;
        try {
            if (null != pmsFullCuts && pmsFullCuts.length > 0) {
                resultFlag = pmsFullCutManager.delete(pmsFullCuts);
            } else {
                LOG.warn("PmsFullCutServiceImpl#batchDelete failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#batchDelete has error.", e);
        }
        return resultFlag;
    }

    public boolean syncFullCutInfo(PmsFullCutRequest fullCutRequest, String isStatusUpdate) {
        return pmsFullCutManager.syncFullCutInfo(fullCutRequest,isStatusUpdate);
    }

    /**
     * {@inheritDoc}
     */
    @Profiled(tag = "PmsFullCutService.getPmsFullCutById")
    public PmsFullCut getPmsFullCutById(Long id) {
        PmsFullCut pmsFullCut = null;
        try {
            if (null != id) {
                pmsFullCut = pmsFullCutManager.getPmsFullCutById(id);
            } else {
                LOG.warn("PmsFullCutServiceImpl#getPmsFullCutById failed, param is illegal.");
            }
        } catch (Exception e) {
            LOG.error("PmsFullCutServiceImpl#getPmsFullCutById has error.", e);
        }
        return pmsFullCut;
    }
}

